from pydantic import BaseModel, Field
from datetime import datetime
from typing import Optional

class UserRoleBase(BaseModel):
    # 必填字段
    user_id: int = Field(..., description="用户ID")
    role_id: int = Field(..., description="角色ID")

class UserRoleCreate(UserRoleBase):
    """创建用户角色关联时使用的模型"""
    
    class Config:
        from_attributes = True

class UserRoleUpdate(BaseModel):
    """更新用户角色关联时使用的模型"""
    user_id: Optional[int] = None
    role_id: Optional[int] = None
    
    class Config:
        from_attributes = True

class UserRole(UserRoleBase):
    id: int
    create_time: Optional[datetime] = Field(None, description="创建时间")
    
    class Config:
        from_attributes = True